#ifndef _FUNCTIONS_H
#define _FUNCTIONS_H

#include "riscv.h"

#define ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b))
#define ROUNDDOWN(a, b) ((a)/(b)*(b))

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)

#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))

char*           safestrcpy(char*, const char*, int);

extern char stack0[];


#define MACHINE_STACK_TOP()({ \
		int harts = r_tp();\
		(void *)(stack0+4096*(harts)) ; })

#define MACHINE_STACK_TOP_K(id)({ \
		(void *)(stack0+4096*(id)) ; })


void timer_print();
#endif
